package test2;

/**
 * @Author Jun jie Yi
 * 2022/4/9 15:46
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Yue {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入总人数：");
        int n = scanner.nextInt();
        System.out.print("请输入报数的大小：");
        int cycleNum = scanner.nextInt();
        yuesefu(n, cycleNum);
        scanner.close();
    }

    public static int yuesefu(int n, int m) {
        // 初始化人数
        List<Integer> start = new ArrayList<Integer>();
        for (int i = 1; i <= n; i++) {
            start.add(i);
        }
        // 从第K个开始计数
        int k = 0;
        while (start.size() > 0) {
            if (start.size() == 1) {
                System.out.println(start.get(k));
                return start.get(k);
            }
            k = k + m;
            // 第m人的索引位置
            k = k % (start.size()) - 1;
            // 判断是否到队尾
            if (k < 0) {
                //System.out.println(start.get(start.size() - 1));
                start.remove(start.size() - 1);
                k = 0;
            } else {

                start.remove(k);
            }
        }
        return 0;
    }
}
